package com.example.kaoqinmanager.utils;

import android.os.Handler;
import android.text.TextUtils;
import android.widget.Toast;

import com.example.kaoqinmanager.InitApplication;


/**
 * @description 弹窗工具类
 * @author fyc
 * @time 2021/1/8
 */
public class MyToast {
    private static Toast mToast;

    public static void showToast(final CharSequence text) {
        if (TextUtils.isEmpty(text)) {
            return;
        }
        final Handler h = InitApplication.getHandler();
        h.post(new Runnable() {
            @Override
            public void run() {
                h.removeCallbacks(r);
                if (mToast == null) {
                    mToast = Toast.makeText(InitApplication.getInstance(), text, Toast.LENGTH_SHORT);
                    mToast.setText(text);
                } else {
                    mToast.setText(text);
                }
                mToast.show();
            }
        });
    }

    private static Runnable r = new Runnable() {
        @Override
        public void run() {
            mToast.cancel();
        }
    };


}
